package com.hckjsec.official.controller;

import java.util.List;

import com.hckjsec.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.official.domain.OfficialRecruit;
import com.hckjsec.official.service.IOfficialRecruitService;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

/**
 * 公司招聘Controller
 * 
 * @author cyt
 * @date 2021-12-10
 */
@RestController
@RequestMapping("/official/recruit")
public class OfficialRecruitController extends BaseController
{
    @Autowired
    private IOfficialRecruitService officialRecruitService;

    /**
     * 查询公司招聘列表
     */
    @GetMapping("/list")
    public TableDataInfo list(OfficialRecruit officialRecruit)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            officialRecruit.setDeptId(SecurityUtils.getDeptId());
        }
        List<OfficialRecruit> list = officialRecruitService.selectOfficialRecruitList(officialRecruit);
        list.forEach(kv->{
            kv.setContent(null);
        });
        return getDataTable(list);
    }

    /**
     * 导出公司招聘列表
     */
    @Log(title = "公司招聘", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OfficialRecruit officialRecruit)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            officialRecruit.setDeptId(SecurityUtils.getDeptId());
        }
        List<OfficialRecruit> list = officialRecruitService.selectOfficialRecruitList(officialRecruit);
        ExcelUtil<OfficialRecruit> util = new ExcelUtil<OfficialRecruit>(OfficialRecruit.class);
        return util.exportExcel(list, "recruit");
    }

    /**
     * 获取公司招聘详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(officialRecruitService.selectOfficialRecruitById(id));
    }

    /**
     * 新增公司招聘
     */
    @Log(title = "公司招聘", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficialRecruit officialRecruit)
    {
        officialRecruit.setDeptId(SecurityUtils.getDeptId());
        officialRecruit.setCreateBy(SecurityUtils.getUsername());
        return toAjax(officialRecruitService.insertOfficialRecruit(officialRecruit));
    }

    /**
     * 修改公司招聘
     */
    @Log(title = "公司招聘", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficialRecruit officialRecruit)
    {
        officialRecruit.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(officialRecruitService.updateOfficialRecruit(officialRecruit));
    }

    /**
     * 删除公司招聘
     */
    @Log(title = "公司招聘", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(officialRecruitService.deleteOfficialRecruitByIds(ids));
    }
}
